//----------------------------------------------------------------------------------
//File: FCMeshCodec.cpp
//Purpose:Implemantation of the class FCMeshCodec
//Details:Decode/encode processing of the collada files	and create the mesh container.
//Data: 20/7/2009
//--------------------------------------------------------------
#include "stdafx.h" 
#include "FCMeshCodec.h"
#include "FCExportImport3D.h"

namespace comms {
cMeshConatainer *FCMeshCodec::Decode(cData &Src) 
{
	if(Src.IsEof()) {
		return NULL;
	}
	return Decode(Src.GetFilePn());
}

cMeshConatainer *FCMeshCodec::Decode(const char *src) 
{
	if(!src) {
		return NULL;
	}
	cMeshConatainer *pMesh = new cMeshConatainer;
	pMesh->SetName(src);
	FCExportImport3D *pIE3D = new FCExportImport3D(src);
	if(pIE3D)
	{
		//decode dae format object to pMesh container
		if(!pIE3D->DecodeObj(*pMesh))
		{
			delete pMesh;
			pMesh = NULL;
		}
	}
	return pMesh;
}
void FCMeshCodec::Encode(const cMeshConatainer &Mesh, cData *To) 
{
	return Encode(Mesh,To->GetFilePn());
}

void FCMeshCodec::Encode(const cMeshConatainer &Mesh, const char *To) 
{
	cAssert(To);
	if(!To) {
		return;
	}
	FCExportImport3D *pIE3D = new FCExportImport3D(To);
	if(pIE3D)
	{
		//encode dae format object from pMesh container
		pIE3D->EncodeObj(Mesh);
	}
}

FCMeshCodec::FCMeshCodec()
{
	FCollada::Initialize();
}

FCMeshCodec::~FCMeshCodec()
{
	FCollada::Release();
}
};

__declspec(dllexport) int GetNumMeshCodecs(){
	return 1;
}

__declspec(dllexport) comms::cMeshCodec* GetMeshCodec(int idx){
	return new comms::FCMeshCodec;
}
__declspec(dllexport) const char* GetMeshCodecName(int idx){
	return "dae";
}
